<template>
  <el-image
    :src="`${imgbaseUrl + src}`"
    alt="image"
    fit="cover"
    :style="`width:${realWidth};height:${realHeight};`"
    :preview-src-list="[imgbaseUrl + src]"
    :preview-teleported="true"
    :zoom-rate="1.2"
    :initial-index="index"
  >
    <template #error>
      <div class="image-slot" style="user-select: none;font-size: 14px;font-weight: bold;font-family: '正楷';">暂无</div>
    </template>
  </el-image>
</template>

<script setup>
import { computed } from "vue";

const imgbaseUrl = import.meta.env.VITE_IMAGE_BASE_URL;

const props = defineProps({
  src: {
    type: String,
    default: "",
  },
  // previewSrcList: {
  //   type: Array,
  //   default: () => [],
  // },
  index: {
    type: Number,
    default: 0,
  },
  width: {
    type: [Number, String],
    default: "",
  },
  height: {
    type: [Number, String],
    default: "",
  },
});

const realWidth = computed(() =>
  typeof props.width == "string" ? props.width : `${props.width}px`
);

const realHeight = computed(() =>
  typeof props.height == "string" ? props.height : `${props.height}px`
);
</script>

<style lang="scss" scoped>
.el-image {
  border-radius: 5px;
  background-color: #ebeef5;
  box-shadow: 0 0 10px 1px #ccc;
  :deep(.el-image__inner) {
    transition: all 0.3s;
    cursor: pointer;
    &:hover {
      transform: scale(1.2);
    }
  }
  :deep(.image-slot) {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    color: #909399;
    font-size: 18px;
  }
}
</style>
